//
//  SYMyCenterVC.m
//  ZCJZ
//
//  Created by sujeking on 2020/3/23.
//  Copyright © 2020 jeking. All rights reserved.
//

#import "SYLoginVC.h"
#import <SSAppRouter/SSAppRouter.h>
#import "ZCBaseUserManager.h"
#import <MJExtension.h>
@interface SYLoginVC ()

@end

@implementation SYLoginVC

- (void)viewDidLoad {
  [super viewDidLoad];
  [self setupUI];
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  self.navigationController.navigationBarHidden = YES;
}

- (void)setupUI {
  @try {
    RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:@{}];
    RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                     moduleName:@"Login"
                                              initialProperties:nil];
    self.view = rootView;
  } @catch (NSException *exception) {
    [self.view makeToast:exception.description duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
  } @finally {
    [self.view makeToast:@"rn 服务器没有开启" duration:2.0 position:CSToastPositionCenter];
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    NSLog(@"rn 服务器没有开启");
  }
}

@end

//*************************************************
//
//*************************************************

@interface SYLoginVCViewModel:NSObject<RCTBridgeModule>
@end
@interface SYLoginVCViewModel()
@end
@implementation SYLoginVCViewModel
RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(showNavbar) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [generalToolBox getcurrentVC].navigationController.navigationBarHidden = NO;
  });
}


RCT_EXPORT_METHOD(pushvc:(NSString *)vcname data:(NSDictionary *)dict) {
  dispatch_async(dispatch_get_main_queue(), ^{
    [SSAppRouter pushViewControllerWithRoute:vcname type:AppRouterManagerType_Native params:dict];
  });
}

RCT_EXPORT_METHOD(updateUserInfo:(NSDictionary *)data) {
  dispatch_async(dispatch_get_main_queue(), ^{
    ZCBaseUserManager *manager = [ZCBaseUserManager shareInstance];
    ZCBaseUserModel *userModel = [ZCBaseUserModel mj_objectWithKeyValues:data];
    manager.userModel = userModel;
  });
}


RCT_EXPORT_METHOD(dismiss) {
  dispatch_async(dispatch_get_main_queue(), ^{
    SYLoginVC *vc = (SYLoginVC *)[generalToolBox getcurrentVC];
    [vc.navigationController dismissViewControllerAnimated:YES completion:^{
      if (vc.dismissCallback) {
        vc.dismissCallback();
      }
    }];
  });
}

@end

